export interface StdResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

export interface FrontPageParams {
  page?: number;
  pageSize?: number;
  field?: string;
  order?: 'ascend' | 'descend';
}

export interface StdPageParams {
  page?: number;
  size?: number;
  order_by?: string;
  order?: 'asc' | 'desc';
  [filters: string]: any;
}

export function StandardizePageParams(p: FrontPageParams | StdPageParams): StdPageParams {
  const fe = p as FrontPageParams;
  if (
    fe.pageSize !== undefined ||
    fe.field !== undefined ||
    fe.order === 'ascend' ||
    fe.order === 'descend'
  ) {
    const x: StdPageParams = {
      page: p.page,
      size: fe.pageSize,
      order_by: fe.field,
      order: fe.order === 'ascend' ? 'asc' : 'desc',
    };
    for (const k in fe) {
      if (k != 'pageSize' && k != 'field' && k != 'order' && k != 'page') {
        // noinspection JSUnfilteredForInLoop
        x[k] = fe[k];
      }
    }
    return x;
  }
  return p as StdPageParams;
}

export interface StdPageResult<T> {
  items: T[];
  total: number;
}

export interface OptionsItem {
  label: string;
  value: string;
}

// unused below

export interface BasicPageParams {
  page: number;
  pageSize: number;
}

export interface BasicFetchResult<T> {
  items: T[];
  total: number;
}
